package Week4;

import java.util.*;

public class Day20 {
}

//牛客:经此一役小红所向无敌
class Main3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextInt() , h = in.nextInt() , b = in.nextInt() , k = in.nextInt();
        long sum = 0;
        long n = Math.min(h / b , k / a);
        sum += (a * n + b * n);
        h -= n * b;
        k -= n * a;

        while(h > 0 && k > 0){
            h -= b;
            k -= a;
            sum += (a + b);
        }

        if(h > 0 || k > 0){
            sum += (h > 0 ? a * 10 : b * 10);
        }
        System.out.println(sum);
    }
}

//牛客:DP6 连续子数组最大和(ACM版本)
class Main4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = in.nextInt();
        }
        int[] dp = new int[n + 1];
        int ret = Integer.MIN_VALUE;
        for(int i = 1; i <= n; i++){
            dp[i] += Math.max(dp[i - 1] , 0) + arr[i - 1];
            ret = Math.max(ret , dp[i]);
        }
        System.out.println(ret);
    }
}

//牛客:非对称之美
class Main5 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int n = s.length;
        boolean flag = false;
        //判断字符串是否全部为相同字符
        for(int i = 1; i < n; i++){
            //只要有一个不是相同字符，就可以结束循环
            if(s[i] != s[0]){
                flag = true;
                break;
            }
        }

        //不是相同字符
        if(flag){
            flag = false;
            //判断整个字符串是否为回文串
            int left = 0 , right = n - 1;
            while(left < right){
                if(s[left] == s[right]){
                    left++;
                    right--;
                }else{
                    //如果不是回文串
                    flag = true;
                    break;
                }
            }
            //如果不是回文串，那么这个字符串的长度就是最长的非回文串的长度
            if(flag) System.out.println(n);
                //如果为回文串，那么这个回文串长度减一就是最长的非回文串的长度
            else System.out.println(n - 1);
        }else{
            //全部都为相同字符就代表整个字符串是一个回文串，没有非回文串
            System.out.println(0);
        }
    }
}